package com.iyundao.io.mapper;

import com.iyundao.io.model.PartyMember;
import com.iyundao.io.tools.PartyMemberShow;
import com.iyundao.io.tools.PartymemberVo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface PartyMemberMapper {
    @Insert({
        "insert into partymember (id, partymembername, ",
        "partymembersex, partymemberbirthday, ",
        "partymemberjointime, partymemberphone, ",
        "partymemberaddress)",
        "values (#{id,jdbcType=INTEGER}, #{partymembername,jdbcType=VARCHAR}, ",
        "#{partymembersex,jdbcType=VARCHAR}, #{partymemberbirthday,jdbcType=DATE}, ",
        "#{partymemberjointime,jdbcType=DATE}, #{partymemberphone,jdbcType=VARCHAR}, ",
        "#{partymemberaddress,jdbcType=VARCHAR})"
    })
    int insert(PartyMember record);

    @InsertProvider(type= PartyMemberSqlProvider.class, method="insertSelective")
    int insertSelective(PartyMember record);

    @Select("select * from partymember where partymemberphone=#{partymemberphone,jdbcType=VARCHAR}")
    PartyMember selectByPhone(String partymemberphone);

    @Select("select * from partymember where id=#{id,jdbcType=INTEGER}")
    PartyMember selectById(Integer id);

    @Select("select id from partymember order by id desc LIMIT 1")
    int selectLastId();

    @Update("update partymember set partymembername=#{partymembername,jdbcType=VARCHAR}, " +
            "partymembersex=#{partymembersex,jdbcType=VARCHAR}, " +
            "partymemberbirthday=#{partymemberbirthday,jdbcType=DATE}, " +
            "partymemberjointime=#{partymemberjointime,jdbcType=DATE}, " +
            "partymemberphone=#{partymemberphone,jdbcType=VARCHAR}, " +
            "partymemberaddress=#{partymemberaddress,jdbcType=VARCHAR} where id=#{id,jdbcType=INTEGER}")
    int updatePartymember(PartyMember partyMember);

    @Select("select p.partymembername,p.id,po.organizationid,sd.real_name realname from partymember p " +
            "inner join activityjoinpeople a " +
            "on p.id = a.partymemberid " +
            "inner join partymemberorganization po " +
            "on p.id = po.partymemberid " +
            " inner join sys_dept sd " +
            "on sd.sid = po.organizationid " +
            "where a.activityid = #{activityid,jdbcType=INTEGER} and po.organizationid != '0' and ISNULL(po.outtime)")
    List<PartymemberVo> selectAllJoinByActivityId(Integer activityid);

    @Select("SELECT * from partymember " +
            "where id in " +
            "(SELECT DISTINCT(partymemberid) from signin " +
            "where activityid = #{activityid,jdbcType=INTEGER} " +
            "and signintime >= #{date,jdbcType=VARCHAR} and signintime <= #{date1,jdbcType=VARCHAR}) ")
    List<PartyMember> selectSignIn(Integer activityid,String date,String date1);

}